<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>HUI</title>
		<link rel="stylesheet" type="text/css" href="./css/hui.css" />
		<style type="text/css">
			body {
				background: #EAEAEC;
				padding: 0px;
				margin: 0px;
			}

			.title {
				width: 200px;
				height: 40px;
				line-height: 40px;
				position: absolute;
				left: 50%;
				margin-left: -100px;
				font-size: 17px;
				color: #000000;

			}

			#hui-back:before {
				color: #2439A5;
			}

			.hui-header {
				background: #FFF;
			}

			.form {
				width: 100%;
				background: #FFFFFF;
				margin-top: 16px;
			}

			.check {
				height: 49px;
				line-height: 49px;
				border-bottom: 1px solid #EAEAEC;
				margin-left: 20px;
				box-sizing: border-box;
				position: relative;
				background: #fff;
			}

			.check:last-child {
				border-bottom: none;
			}

			.hint {
				font-size: 17px;
				color: #333333;
			}

			.import {
				border: 0px;
				position: absolute;
				left: 100px;
				height: 30px;
				width: 200px;
				top: 50%;
				margin-top: -15px;
				font-size: 16px;
			}

			.btn {
				background: #2439A5;
				text-align: center;
				margin: 16px;
				height: 47px;
				line-height: 47px;
				border-radius: 24px;
				font-size: 18px;
				color: #FFFFFF;
				margin-top: 48px;
			}

			.warn {
				height: 36px;
				line-height: 36px;
				background: #FDFCEC;
				color: #F86E21;
				font-size: 14px;
				padding-left: 15px;
			}

			.information {
				position: absolute;
				right: 15px;
				color: #999999;
				font-size: 16px;
			}
		</style>
	</head>

	<body>
		<header class="hui-header">
			<div id="hui-back"></div>
			<span class="title">驾驶证</span>
		</header>
		<div class="hui-wrap">
			<div class="warn">
				没有驾驶证信息（需要先授权查询）
			</div>
			<div class="check" style="margin-left: 0px;padding-left: 18px;">
				<span class="hint">姓名</span>
				<span id="a1" class="information">张琪</span>
			</div>
			<div class="check" style="margin-left: 0px;padding-left: 18px;">
				<span class="hint">身份证</span>
				<span id="a2" class="information">110222199001012345</span>
			</div>
			<div class="check" style="margin-left: 0px;padding-left: 18px;">
				<span class="hint">付费方式</span>
				<span class="information">微信</span>
			</div>
			<div class="check" style="margin-left: 0px;padding-left: 18px;">
				<span class="hint">付费金额</span>
				<span id="a4" class="information">5.00元</span>
			</div>
			<div id="ev" class="btn">支付</div>
		</div>
		<script src="js/jquery.min.js"></script>
		<script src="./js/hui.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/chen-url.js"></script>
		<script>
			var je = 0;
			hui.ready(function() {
				hui('#a1').html(localStorage.getItem("name"));
				hui('#a2').html(localStorage.getItem("idNumber"));
				// 获取付费金额
				hui.getJSON(
					address + "service/data1.json",
					function(obj) {
						if (obj.code == 200) {
							for (var p in obj.data) {
								if (obj.data[p].type == "1") {
									je = obj.data[p].monery;
									hui('#a4').html((parseInt(obj.data[p].monery) / 100) + " 元");
								}
							}
						} else {
							hui.iconToast('获取驾驶证支付信息失败，请退出后重试！', 'warn');
						}


						if (je == 0) {
							hui('#ev').html('免费提交');
						} else {
							hui('#ev').html('微信支付');
						}
					},
					function(e) {
						hui.iconToast('获取驾驶证支付信息失败，请退出后重试！', 'warn');
					}
				);
			});

			hui('#ev').click(function() {
				var uid = localStorage.getItem("id");
				if (hui(this).buttonIsLoading()) {
					return false;
				}
				hui(this).loadingButton('加载中...');
				setTimeout(function() {
					hui('#ev').resetLoadingButton();

					if (je != 0) {
						var result = false;
						nativeMethod.jszPay(uid, localStorage.getItem("name"),
							localStorage.getItem("idNumber"),
							localStorage.getItem("uasername"),
							je);

						// 轮训查询订单
						// var result = false;
						// var my = setInterval(function() {
						// 	if (!result) {
						// 		result = getJSZ(uid);
						// 	} else {
						// 		// 跳转
						// 		clearInterval(my)
						// 		hui.open("./jsz.html")
						// 	}
						// }, 1000);


					} else {
						hui.alert('免费提交！', '好的', function() {
							var flag = nativeMethod.freeJSZ(localStorage.getItem("id"), localStorage.getItem("name"),
								localStorage.getItem("idNumber"),
								localStorage.getItem("username"));
							// var flag = nativeMethod.getSaveJSZ(localStorage.getItem("id"));
							hui.iconToast('保存' + flag, 'warn');
							if (flag) {
								if (getJSZ(localStorage.getItem("id"))) {
									hui.open("./jsz.html")
								}
							} else {
								hui.iconToast('保存驾驶证信息失败，请退出后重试！', 'warn');
							}
						})




						// 						hui.alert('免费提交！', '好的', function() {
						// 							setTimeout(function() {
						// 								var flag = nativeMethod.freeJSZ(uid, localStorage.getItem("name"),
						// 									localStorage.getItem("idNumber"),
						// 									localStorage.getItem("username"));
						// 									
						// 									if(flag){
						// 										hui.iconToast('！'+fla, 'warn');
						// 										getJSZ(localStorage.getItem("id"));
						// 									}else{
						// 										hui.iconToast('保存驾驶证信息失败，请退出后重试！', 'warn');
						// 									}
						// 								
						// 								
						// 							}, 2000);
						// 							var flag = nativeMethod.freeJSZ(uid, localStorage.getItem("name"),
						// 								localStorage.getItem("idNumber"),
						// 								localStorage.getItem("username"));
						// 
						// 							if (flag) {
						// 								hui.iconToast('！' + fla, 'warn');
						// 								getJSZ(localStorage.getItem("id"));
						// 								hui.open("./jsz.html")
						// 							} else {
						// 								hui.iconToast('保存驾驶证信息失败，请退出后重试！', 'warn');
						// 							}
						// 							
						// 						});
					}
				}, 200);
			});


			function getJSZ(uid) {
				var r = false;
				$.ajax({
					type: 'POST',
					url: address + 'service/jsz/one',
					data: {
						uid: uid
					},
					async: false,
					success: function(obj) {
						if (obj.msg == "ok") {
							r = true;
							// 缓存驾驶证数据
							localStorage.setItem("firstIssueDate", obj.data.firstIssueDate);
							localStorage.setItem("licenseClass", obj.data.licenseClass);
							localStorage.setItem("validFrom", obj.data.validFrom); // 有效起始时间
							localStorage.setItem("licenseData", parseInt(obj.data.validTo.substring(0, 4)) - parseInt(obj.data.validFrom
								.substring(0, 4))); // 有效期
							localStorage.setItem("licenseStatus", obj.data.licenseStatus);
						} else {
							r = false;
						}
					},
					error: function(err) {
						r = false;
					},
					dataType: 'json'
				});
				return r;
			}
		</script>
	</body>

</html>
